package model;

import java.util.Date;

import utility.conversion;

public class storage {
	public enum Category { Ammo, Weapon, Clothes }
	private int id;
	private Category category;
	private String storeman;
	private String goodName;
	private Date from;
	private Date to;
	final static int field_count = 6;
	
	// Getters and setters
	public Category getCategory() {
		return category;
	}
	public void setCategory(String category) {
		try {
			this.category = Category.valueOf(category);			
		}
		catch (Exception e){
			System.out.println("Wrong category value: " + e.getMessage());
		}
	}
	public String getStoreman() {
		return storeman;
	}
	public void setStoreman(String storeman) {
		this.storeman = storeman;
	}
	public String goodName() {
		return goodName;
	}
	public void setGoodName(String goodName) {
		this.goodName = goodName;
	}
	public Date getFrom() {
		return from;
	}
	public void setFrom(String from) {
		this.from = conversion.parseStringToDate(from);
	}
	public Date getTo() {
		return to;
	}
	public void setTo(String to) {
		this.to = conversion.parseStringToDate(to);
	}
	public void fillObject(String detail) {
		String str[] = detail.split("\t");
		setId(str[0]);
		setCategory(str[1]);
		setStoreman(str[2]);
		setGoodName(str[3]);
		setFrom(str[4]);
		if (str.length == field_count)
			setTo(str[5]);
	}
	
	public int getId() {
		return id;
	}
	public void setId(String id) {
		this.id = Integer.parseInt(id);
	}
	
	@Override
	public String toString() {
		return id + "\t" + category + "\t" + storeman + "\t" + goodName + "\t" + conversion.parseDateToString(from) + "\t" + conversion.parseDateToString(to);
	}

}
